<!-- 预立项申请 -->
<template>
	<view class="page">
		<u--form
			labelPosition="top"
			:model="model"
			ref="hmform"
			:rules="rules"
			labelWidth="auto"
			:labelStyle="{
				fontSize: '14px',
				color: '#B2B2B2',
				lineHight: '20px'
			}"
		>
			<view class="basic-style">
				<u-form-item
					label="单据编号"
					prop="billNo"
					:borderBottom="false"
					required
				>
					<u--input
						disabled
						placeholder="请输入单据编号"
						v-model="model.billNo"
					></u--input>
				</u-form-item>
				<u-form-item
					label="申请时间"
					prop="createTime"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.createTime"
						disabled
						placeholder="请选择申请时间"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="申请人"
					prop="proposer"
					:borderBottom="false"
					required
				>
					<h-select-person-input
						style="width: 100%"
						disabled
						v-model="model.proposer"
						placeholder="请选择申请人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.proposer"
					></h-select-person-input>
				</u-form-item>
				
				
				
				<u-form-item
					label="申请部门"
					prop="proposerDeptId"
					:borderBottom="false"
					required
				>
					<h-select-depart-input
					  disabled
					  v-model="model.proposerDeptId"
					  :departName="model.proposerDeptText"
					  placeholder="请选择部门"
					  border="surround"
					  style="width: 100%"
					  suffixIcon="arrow-down-fill"
					  :suffixIconStyle="{ color: '#B2B2B2' }"
					  :title.sync="model.proposerDeptText"
					  @detail="ontenderDeptDetail"
					></h-select-depart-input>
				</u-form-item>
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">基本信息</view>
					<u-line :length="120"></u-line>
				</view>
				<u-form-item
					label="项目名称"
					prop="mc"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.mc"
						placeholder="请输入项目名称"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="经营团队"
					prop="ywtd"
					:borderBottom="false"
					required
				>
					<h-select-team-input
					  @input="changeBusinessCompany"
						style="width: 100%;"
						v-model="model.ywtd"
						objectField="model.ywtd"
						placeholder="请选择经营团队"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						:tdlx="1"
					></h-select-team-input>
				</u-form-item>
				<!-- <u-form-item
						label="经营公司"
						prop="businessCompanyId"
						:borderBottom="false"
						required
					>
						<h-select-company-input
						  disabled
							style="width: 100%"
							v-model="model.businessCompanyId"
							border="surround"
							placeholder="请选择经营公司"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
							objectField = 'managerTrusteeForm.gsdaId'
						></h-select-company-input>
					</u-form-item> -->
				<u-form-item
					label="项目承接人"
					prop="cjr"
					:borderBottom="false"
					required
				>
					<h-select-person-input
						style="width: 100%"
						v-model="model.cjr"
						placeholder="请选择项目承接人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.cjr"
					></h-select-person-input>
				</u-form-item>
				<u-form-item
					label="是否环评项目"
					prop="sfhpxm"
					:borderBottom="false"
					required
				>
					<h-dict-radio v-model="model.sfhpxm" dictName="yn"></h-dict-radio>
				</u-form-item>
				<u-form-item
					label="签订单位"
					prop="qddw"
					:borderBottom="false"
					required
				>
					<h-select-company-input
						style="width: 100%;"
						v-model="model.qddw"
						objectField="model.qddw"
						placeholder="请选择签订单位"
						border="surround"
						suffixIcon="arrow-down-fill"
						@input="onCompanyChange"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-select-company-input>
				</u-form-item>
				<u-form-item
					label="业绩归属年度"
					prop="yjgsnd"
					:borderBottom="false"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.yjgsnd" 
						placeholder="请选择业绩归属年度" 
						dictName="yjgsnd" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="业主单位"
					prop="yzdw"
					:borderBottom="false"
					required
				>
					<h-select-customer-input
						style="width: 100%"
						v-model="model.yzdw"
						commercialType= "1"
						border="surround"
						placeholder="请选择业主单位"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField = 'model.yzdw'
						@input="onCustomerChange"
					></h-select-customer-input>
				</u-form-item>
				<u-form-item
					label="联系人"
					prop="lxr"
					:borderBottom="false"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.lxr" 
						placeholder="请选择联系人" 
						:dictName="cust_lxr" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
						@change="lxrChange"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="联系电话"
					prop="lxdh"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.lxdh"
						placeholder="请输入联系电话"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="项目所在地址"
					prop="ssq"
					:borderBottom="false"
					required
				>
					<h-select-address-input
						style="width: 100%"
						v-model="model.ssq"
						placeholder="请选择项目地址"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-select-address-input>
				</u-form-item>
				<u-form-item
					label="项目详细地址"
					prop="projectAddress"
					:borderBottom="false"
					required
				>
					<u--input
						placeholder="请输入项目详细地址"
						v-model="model.projectAddress"
					></u--input>
				</u-form-item>
				<u-form-item
					label="项目来源"
					prop="xmly"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.xmly" 
						placeholder="请选择项目来源" 
						dictName="xmly_type"
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="预计合同额(元)"
					prop="yjhte"
					:borderBottom="false"
					ref="item1"
					required
				>
					<u--input
						type="number"
						placeholder="请输入预计合同额"
						v-model="model.yjhte"
						@change="convertMoney2"
						@blur="convertMoneyBlur2"
					></u--input>
				</u-form-item>
				<u-form-item
					label="大写预计合同额(元)"
					prop="dx"
					:borderBottom="false"
					ref="item1"
				>
					<u--input
						disabled
						placeholder="请输入大写预计合同额"
						v-model="model.dx"
					></u--input>
				</u-form-item>
				<u-form-item
					label="立项事由及说明"
					prop="lxsyjsm"
					:borderBottom="false"
					ref="item1">
					<!-- #ifdef H5 -->
					<u--textarea
						v-model="model.lxsyjsm"
						placeholder="请输入立项事由及说明"
						confirm-type="done"
						maxlength="500"
					></u--textarea>
					<!-- #endif -->
					<!-- #ifndef H5 -->
					<u--textarea
						v-model="model.lxsyjsm"
						:confirmType="null"
						count
						placeholder="请输入立项事由及说明"
						:maxlength="500"
					></u--textarea>
					<!-- #endif -->
				</u-form-item>
			</view>
			
			<!-- 附件 -->
			<view class="basic-style">
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">相关附件</view>
					<u-line :length="120"></u-line>
				</view>
				<view class="warning">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
				<view class="" style="width: 100%;">
					<h-upload-file v-model="model.xgfj" :isIcon="false" ></h-upload-file>
					<file-list v-if="model.xgfj" v-model="model.xgfj" :isDelete="true"></file-list>
				</view>
			</view>
			<view class="basic-style">
				<view class="basic-title-center">
					<u-line :length="105"></u-line>
					<view class="">业务分类信息</view>
					<u-line :length="105"></u-line>
				</view>
				<ErpOmcPrepareProjectItemForm @ok="onInforList" :dataList="dataSource"></ErpOmcPrepareProjectItemForm>
			</view>
			<!-- 附件 -->
			<view class="basic-style">
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">用印信息</view>
					<u-line :length="120"></u-line>
				</view>
				<u-form-item
					label="报价文件用印"
					prop="isSeal"
					:borderBottom="false"
					required>
					<h-dict-radio v-model="model.isSeal" dictName="yn" @input="handleChangeSeal"></h-dict-radio>
				</u-form-item>
				<view v-if="model.isSeal == '1'">
					<u-form-item label="用印类型" prop="signSealWay" required>
					  <h-select-input-tag
					    class="w-100"
					    v-model="model.signSealWay"
					    objectField="model.signSealWay"
					    placeholder="请选择用印类型"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
					    border="surround"
					    dictName="seal_way"
					  ></h-select-input-tag>
					</u-form-item>
					<u-form-item
						label="是否借出"
						prop="lendYn"
						:borderBottom="false"
						required>
						<h-dict-radio v-model="model.lendYn" dictName="yes_no"></h-dict-radio>
					</u-form-item>
				  <u-form-item label="文件份数" prop="quantity" required>
						<h-number-input placeholder="请输入文件份数" v-model="model.quantity" :digit="0" :min="0" :max="99999999"></h-number-input>
				  </u-form-item>
					<u-form-item
						required
						label="用印说明"
						prop="userExplain"
						:borderBottom="false"
						ref="item1">
						<!-- #ifdef H5 -->
						<u--textarea
							v-model="model.userExplain"
							placeholder="请输入用印说明"
							confirm-type="done"
							:maxlength="500"
						></u--textarea>
						<!-- #endif -->
						<!-- #ifndef H5 -->
						<u--textarea
							v-model="model.userExplain"
							:confirmType="null"
							count
							:maxlength="500"
							placeholder="请输入用印说明"
						></u--textarea>
						<!-- #endif -->
					</u-form-item>
					<u-form-item label="选择印章" prop="sealIds" :borderBottom="false" required>
						<h-select-seal-input style="width: 100%;" v-model="model.sealIds" objectField="model.sealIds"
							placeholder="请选择印章" border="surround" suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}" :sealCompany="model.qddw">
						</h-select-seal-input>
					</u-form-item>
					<template>
						<SealFormInfo
							v-for="(item, index) in formData"
							:key="index"
						  :item="item"
						  :index="index"
						/>
					</template>
				</view>
			</view>
			<view class="basic-style" v-if="model.isSeal == '1'">
			  <view class="basic-title basic-border">用印文件<span style="color: #faad14;font-weight: 600">（请上传只需盖章的用印文件！）</span></view>
			  <u-form-item label="用印文件" prop="signFile" required>
					<view class="py-1 space-y-1" style="width: 100%">
						<view style="color: red">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
						<h-upload-file v-model="model.signFile" :fillSize="50" :isIcon="false" :isSingle="true" fileType=".pdf, .PDF, .doc, .docx" fileTypeText="请上传word与pdf格式的文件！"></h-upload-file>
						<file-list v-if="model.signFile" v-model="model.signFile" :isDelete="true"></file-list>
					</view>
				</u-form-item>
			</view>
		</u--form>
		
		<view class="space-x-1 px-1 btn_position">
			<u-button :disabled="isSubmit" type="primary" :plain="true" text="保存" @click="onDrafts"></u-button>
			<u-button :disabled="isSubmit"  type="primary"  text="保存并提交" @click="onSubmit"></u-button>
		</view>
		<view style="height: 100rpx;"></view>
		<u-toast ref="uToast"></u-toast>
		<ProcessNodeConfiguration ref="processConfig" @ok="onOk"></ProcessNodeConfiguration>
	</view>
</template>

<script>
import fileList from '@/pages/synergy/components/fileList.vue'
import ErpOmcPrepareProjectItemForm from './components/ErpOmcPrepareProjectItemForm.vue' // 业务分类组件
import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue' // 流程节点配置人员选择弹窗
import http from '@/utils/request'
import SealFormInfo from '@/pages/seal/components/SealFormInfo.vue'
import {
	generatedFormNumber, // 获取单据编号
	erpOmcCustomerManagerContactId, // 获取联系方式
	erpOmcPrepareProjectAdd, // 添加
	erpOmcPrepareProjectEdit, // 编辑
	erpOmcPrepareProjectId, // 详情
	queryByIdQualificationChild, // 印章列表
	getPrepareProjectChild // 获取业务分类信息列表
} from '@/api/index.js'
import moment from 'moment'
import {
	BASE_URL
} from '@/utils/baseUrl.js'
import { convertCurrency } from '@/utils/MoneyConvert' // 金额大写转换
export default {
	components: {
		fileList,
		ErpOmcPrepareProjectItemForm,
		ProcessNodeConfiguration,
		SealFormInfo
	},
	data() {
		return {
			isSubmit: false,
			formData: [], // 印章列表
			model: {
				billNo: '', //单据编号
				businessCompanyId:'', // 经营公司
				createTime: '', // 申请时间
				proposer: '', // 申请人
				proposerDeptId: '', // 申请部门
				mc: '', // 项目名称
				ywtd: '', // 经营团队
				cjr: '', // 项目承接人
				sfhpxm: '', //是否环评项目
				qddw: '', //签订单位
				yjgsnd: '', // 业绩发归属年度
				yzdw: '', // 业主单位
				lxr: '', // 联系人
				lxdh: '', // 联系电话
				ssq: '', // 项目所在地址
				projectAddress: '', // 项目详细地址
				xmly: '' ,// 项目来源
				yjhte: '', // 预计合同额
				dx: '', // 预计合同额大写
				lxsyjsm : '', // 立项事由及说明
				xgfj: '', // 相关附件
				isSeal: '0', // 报价文件用印
				signSealWay: '', // 用印类型
				lendYn: '', // 是否借出
				quantity: '', // 文件份数
				userExplain: '', // 用印说明
				sealIds: '', // 选择印章
				signFile: '', // 用印文件
			},
			cust_lxr: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0',
			id: '', // 详情id值
			dataSource: [], // 业务分类信息列表
			rules: {
				billNo: [{ required: true, message: '请输入单据编号!', trigger: ['blur', 'change'] }],
				proposerDeptId: [{ required: true, message: '请选择申请部门!', trigger: ['blur', 'change'] }],
				proposer: [{ required: true, message: '请选择申请人!', trigger: ['blur', 'change'] }],
				createTime: [{ required: true, message: '请选择申请时间!', trigger: ['blur', 'change'] }],
				
				sfhpxm: [
					{ required: true, message: '请选择是否环评!', trigger: ['change','blur'], },
				],
				mc: [
					{ required: true, message: '请输入项目名称!', pattern: '[^ \x22]+', trigger: ['change','blur'] },
					{
						asyncValidator: (rule, value, callback) => {
							let params = {
								projectName: value,
								type: 'prepare' // 立项：project  预立项：prepare
							}
							http.get('/api/erp/omc/project/erpOmcProject/checkProjectDuplicate', params).then(res => {
								// 如果验证不通过，需要在callback()抛出new Error('错误提示信息')
								if (res.success) {
									callback();
								} else {
									callback(new Error(res.message));
								}
							}).catch(err => {
								callback(new Error(err.message));
							})
						},
						trigger: ['blur']
					}
				],
				ywtd: [
					{ required: true, message: '请选择经营团队!', trigger: ['change','blur'], },
				],
				cjr: [
					{ required: true, message: '请选择项目承接人!', trigger: ['change','blur'], },
				],
				qddw: [
					{ required: true, message: '请选择签订单位!', trigger: ['change','blur'], },
				],
				yjgsnd: [
					{ required: true, message: '请选择业绩归属年度!', trigger: ['change'], },
				],
				yzdw: [
					{ required: true, message: '请选择业主单位!', trigger: ['change','blur'], },
				],
				lxr: [
				  {  required: true, message: '请输入联系人!', trigger: ['change','blur'] },
				],
				lxdh: [
						{ required: true, message: '请输入联系电话!', trigger: ['change', 'blur'] },
						{ required: true, pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系电话!', trigger: ['change', 'blur'] }
					  
				],
				ssq: [
					{ required: true, message: '请选择省市区!', trigger: ['change','blur'], },
				],
				projectAddress: [
					{ required: true, message: '请输入详细地址!', trigger: ['change','blur'] },
				],
				xmly: [
					{ required: true, message: '请选择项目来源!', trigger: ['change','blur'], },
				],
				yjhte: [
					{ type: 'number', required: true, message: '请输入预计合同额!', trigger: ['change','blur'] },
				],
				isSeal: [
					{ required: true, message: '请选择报价文件用印!', trigger: ['change','blur'] },
				],
				signSealWay: [
					{ required: true, message: '请选择用印类型!', trigger: ['change','blur'] },
				],
				lendYn: [
					{ required: true, message: '请选择是否借出!', trigger: ['change'] },
				],
				quantity: [
					{ required: true, message: '请输入文件份数!', trigger: ['change','blur'] },
				],
				userExplain: [
					{ required: true, message: '请输入用印说明!', trigger: ['change','blur'] },
				],
				sealIds: [
					{ required: true, message: '请选择印章!', trigger: ['change','blur'] },
				],
				signFile: [
					{ required: true, message: '请选择用印文件!', trigger: ['change','blur'] },
				],
			},
			
			
			//代码生成后需手动设置流程编码
			flowCode: 'dev_erp_omc_prepare_project_001',
			beanName: 'erpOmcPrepareProjectServiceImpl',
			formUrl: 'erp/omc/prepareproject/modules/ErpOmcPrepareProjectForm',
			formUrlMobile: '/pages/synergy/erpOmcPrepareProjectDetail',
			processId: '1557666877169283074'
		};
	},
	onLoad(options) {
		this.id = options.id || ''
		if (options.id) {
			// 编辑
			this.edit(options.id)
		} else {
			// 添加
			this.add()
		}
		
	},
	watch: {
		'model.sealIds': {
			handler (val) {
				this.getChildData(val)
			},
			immediate: true
		}
	},
	methods: {
     
		changeBusinessCompany(val){
			this.model.businessCompanyId = val.belongCompanyId
			
		},

		// 获取印章列表
		getChildData(ids){
			if (!ids){
				this.formData = []
				return false
			}
			queryByIdQualificationChild({ ids}).then(res => {
				if(res.success){
					this.formData = res.result || []
					if (res.result && res.result.length) {
						var sealIds_dictText = ''
						res.result.map(value => {
							sealIds_dictText = sealIds_dictText  + ',' + value.sealType_dictText?value.sealType_dictText:value.sealType
						})
						sealIds_dictText = sealIds_dictText.slice(1) 
						this.formData.sealIds_dictText = sealIds_dictText
					}
					
				}
			})
		},
		// 选择保价文件用印
		handleChangeSeal(val) {
			if (val == '1') {
				this.$refs.hmform.clearValidate(['signSealWay', 'lendYn', 'quantity', 'userExplain', 'sealIds', 'signFile']);
			}
			this.$set(this.model, 'signSealWay', '')
			this.$set(this.model, 'lendYn', '')
			this.$set(this.model, 'quantity', '')
			this.$set(this.model, 'userExplain', '')
			this.$set(this.model, 'sealIds', '')
			this.$set(this.model, 'signFile', '')
		},
		// 编辑
		async edit(id) {
			// 获取详情
			this.getDetail(id)
			getPrepareProjectChild({ mainId: id }).then(res => {
				if (res.success) {
					this.dataSource = res.result.records || res.result
				}
			})
		},
		// 印章资质所属公司
		onCompanyChange (item) {
			this.$set(this.model, 'sealIds', '')
		},
		// 获取详请
		getDetail (id) {
			erpOmcPrepareProjectId({ id }).then( async res => {
				if (res.success) {
					this.cust_lxr = await 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + res.result.yzdw + '\'';
					this.model = await {...res.result};
					if (this.model.yjgsnd){
						this.model.yjgsnd = this.model.yjgsnd + ''
					}
					if (this.model.sfhpxm !== null || this.model.sfhpxm !== ''){
						this.model.sfhpxm = this.model.sfhpxm + ''
					}
					if (this.model.lendYn !== null || this.model.lendYn !== ''){
						this.model.lendYn = this.model.lendYn + ''
					}
					if (this.model.yjhte !== null || this.model.yjhte !== '') {
						this.model.yjhte = this.model.yjhte?.toFixed(2)
						this.$set(this.model, 'dx', convertCurrency(this.model.yjhte))
					}
				}
			})
		},
		
		// 获取流程列表
		getProcessList (id) {
			if (this.isSubmit) {
				this.$refs.processConfig.showPopup = true
				this.$refs.processConfig.formUrl = this.formUrl
				this.$refs.processConfig.formUrlMobile = this.formUrlMobile
				this.$refs.processConfig.flowCode = this.flowCode
				this.$refs.processConfig.edit(id, this.processId, this.beanName)
			}
		},
		
		// 投标部门详情
		ontenderDeptDetail(item) {
		  var title = ''
		  if (item && item.length) {
		    item.map((value, index) => {
		      title = value.departName + ',' + title
		    })
		    title = title.substring(0, title.lastIndexOf(','))
		  }
		  this.model.proposerDeptText = title
		},
		
		// 添加
		add() {
			this.getGeneratedFormNumber()
			this.model.createTime = moment().format('YYYY-MM-DD HH:mm'); // 申请时间
			this.model.proposer = uni.getStorageSync('userInfo').empId; //申请人
			this.model.proposerDeptId = uni.getStorageSync('userInfo').deptId; //申请部门
		},
		// 获取单据编号
		getGeneratedFormNumber() {
			generatedFormNumber({ prefix: 'YLX', subSystemCode: '05' }).then(res => {
				if (res.success) {
					this.$set(this.model, 'billNo', res.result)
				}
			})
		},
		
		// 修改本次合同额大写和修改任务信息中的合同占比
		convertMoney2(item) {
			let money = Number(this.model.yjhte)
			this.$set(this.model, 'dx', convertCurrency(money))
		},
		// 监听修改本次合同额数据
		convertMoneyBlur2 (item) {
			let money = Number(this.model.yjhte)
			if (this.model.yjhte) {
				this.$set(this.model, 'yjhte', money.toFixed(2))
				this.convertMoney2()
			}
		},
		
		// 选择业主单位
		onCustomerChange () {
			this.$set(this.model, 'lxr', null)
			this.$set(this.model, 'lxdh', '')
			this.cust_lxr = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.yzdw + '\'';
		},
		// 选择联系人
		lxrChange (val) {
			var params = {id: val}
			erpOmcCustomerManagerContactId(params).then(res => {
				if (res.success) {
					this.$set(this.model, 'lxdh', res.result.lxfs)
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		onInforList (item) {
			this.dataSource = item
		},
		
		validateForm () {
			let _this = this
			return this.$refs.hmform.validate().then(async resp => {
				let params = {
					projectName: _this.model.mc,
					type: 'prepare' // 立项：project  预立项：prepare
				}
				if(_this.dataSource == null ||_this.dataSource.length <= 0){
					_this.$refs.uToast.show({
						message: '必须填写业务分类信息！',
						type: 'error'
					})
					return Promise.reject('必须填写业务分类信息！')
				}
				return http.get('/api/erp/omc/project/erpOmcProject/checkProjectDuplicate', params).then(async res => {
					// 如果验证不通过，需要在callback()抛出new Error('错误提示信息')
					if (!res.success) {
						return Promise.reject(res.message)
					}
				}).catch(async err => {
					return Promise.reject(err.message)
				})
			})
		},
		// 点击提交
		async onSubmit () {
			await this.validateForm()
			this.isSubmit = true
			this.model.itemList = this.dataSource;
			let httpurl = '';
			if (!this.id) {
				httpurl = erpOmcPrepareProjectAdd;
			} else {
				httpurl = erpOmcPrepareProjectEdit;
			}
			httpurl(this.model).then(res => {
				if (res.success) {
					var that = this
					// 获取流程列表
					if (this.id) {
						this.getProcessList(this.id)
					} else {
						// 判断添加的时候是否有返回id值
						if (res.result) {
							this.getProcessList(res.result)
						}
						
					}
					this.$refs.uToast.show({
						message: res.message,
						type: 'default',
						complete () {
							// that.isSubmit = false
						}
					})
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
			// this.$refs.hmform.validate().then(res => {
			// 	if(res){
					
			// 	}
			// })
		},
		
		onDrafts() {
			// if(this.dataSource == null ||this.dataSource.length <= 0){
			// 	// that.$message.warning('必须填写业务分类信息！');
			// 	this.$refs.uToast.show({
			// 		message: '必须填写业务分类信息！',
			// 		type: 'error'
			// 	})
			// 	return
			// }
			this.isSubmit = true
			this.model.itemList = this.dataSource || [];
			let httpurl = '';
			if (!this.id) {
				httpurl = erpOmcPrepareProjectAdd;
			} else {
				httpurl = erpOmcPrepareProjectEdit;
			}
			httpurl(this.model).then(res => {
				if (res.success) {
					var that = this
					this.$refs.uToast.show({
						message: res.message,
						type: 'default',
						complete () {
							that.isSubmit = false
							// uni.navigateBack()
							if (getCurrentPages().length > 1) {
								uni.navigateBack()
							} else {
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}
							
						}
					})
					
					
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
			
		},
		
		// 提交流程成功
		onOk () {
			this.$refs.uToast.show({
				message: '提交成功',
				type: 'success',
				complete () {
					if (getCurrentPages().length > 1) {
						uni.navigateBack()
					} else {
						uni.reLaunch({
							url: '/pages/home/home'
						})
					}
					
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
@import url("@/assets/inputStyle.scss");
.basic-title-center {
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 16px;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 600;
	color: #333333;
	text-align: center;
}

// 评测信息
.info-title{
	font-size: 14px;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #171717;
	line-height: 40rpx;
	padding-bottom: 16rpx;
}

// 评测结果
.result-style{
	font-size: 12px;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #B2B2B2;
}

.inforamtion{
	margin-top: 10rpx;
	padding: 10rpx;
	border-radius: 15rpx;
	box-shadow: 0px 4px 20px 0px rgba(0,0,0,0.1);
}
.warning{
	color: #f56c6c;
	margin-bottom: 20rpx;
}
</style>